import { getAreaObj } from '@/utils/util'
import { BaseFormConfig, ExtendFormConfig, OtherFormConfig } from './components/config'
import { toSearchHandle, configToSearch, configToReserveSearch } from '@/views/datacenter/basicData/utils/index'
import { multiply } from 'lodash-es'

export const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ label: '所属区域', prop: 'tableAreaName', width: 200 },
		{ label: '机构名称', prop: 'organizationName' },
		{
			label: '统一社会信用代码',
			prop: 'creditCode',
		},
		{ label: '联系人', prop: 'burdenUserName' },
		{ label: '联系方式', prop: 'burdenUserPhone' },
		{
			label: '机构类型',
			prop: 'organizationTypeLabel',
		},
		{
			label: '机构评定星级',
			prop: 'organizationLevelLabel',
		},
		{
			label: '是否备案',
			prop: 'filingFlagLabel',
		},
		{
			label: '床位总数',
			prop: 'bedTotalNum',
		},
		// {
		// 	label: '收住老人',
		// 	prop: 'refugeTotalOldmanNum',
		// },
		{ label: '入库时间', prop: 'createTime' },
		{
			label: '上链状态',
			prop: 'onBlockchainFlag',
			api: 'geiDictItemList',
			type: 'remoteSelect',
			code: 'BLOCK_CHAIN_STATUS',
			tipProp: 'onBlockchainTime',
			tipLabel: '上链时间',
		},
		{ label: '材料完整度', prop: 'integrity' },
		{
			label: '操作',
			prop: 'menu',
			fixed: 'right',
			width: 200,
		},
	],
}

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	labelWidth: '75',
	column: [
		{
			label: '信用代码',
			prop: 'creditCode',
			type: 'input',
			span: 6,
		},
		{
			label: '机构名称',
			prop: 'organizationName',
			type: 'input',
			span: 6,
		},
		{
			label: '联系人',
			prop: 'burdenUserName',
			type: 'input',
			span: 6,
		},
		{
			label: '联系方式',
			prop: 'burdenUserPhone',
			type: 'input',
			span: 6,
		},
		{
			label: '所属地区',
			prop: 'areas',
			type: 'AplidAreaSelect',
			span: 6,
		},
		{
			label: '机构类型',
			prop: 'organizationTypeList',
			type: 'remoteSelect',
			code: 'ORG_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: true,
			span: 6,
		},
		{
			label: '机构星级',
			prop: 'organizationLevel',
			type: 'remoteSelect',
			code: 'ORG_LEVEL',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 6,
		},
		{
			label: '运营状态',
			prop: 'operateStatus',
			changeField: true,
			type: 'remoteSelect',
			code: 'ORG_OPERATE_STATUS',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 6,
		},
	],
}
const reserveSearchConfig: any = {
	inline: true,
	showBtn: false,
	labelPosition: 'left',
	column: [
		...configToReserveSearch(BaseFormConfig.column),
		// ...configToReserveSearch(ExtendFormConfig.column),
		// ...configToReserveSearch(OtherFormConfig.column),
	],
}
const moreSearchConfig: any = {
	inline: true,
	showBtn: false,
	labelPosition: 'left',
	column: [
		...configToSearch(BaseFormConfig.column),
		//  ...configToSearch(ExtendFormConfig.column),
		//   ...configToSearch(OtherFormConfig.column)
	],
}
export const detailConfig = {
	customeHeader: {
		integrityConfig: {
			baseTableName: 'dp_service_org_base',
			materialTableName: 'dp_service_org_material',
			soleValue: 'creditCode',
		},
		type: 'CardOne',
		title: 'organizationName',
		avatar: 'organizationLogo',
		tipList: [],
		tagList: [],
		menuBtn: [
			{
				icon: 'delete',
				label: '删除服务组织',
				type: 'danger',
				operate: 'delete',
				auth: 'view_dpServiceOrgBase_del',
				text: false,
				show: true,
				plain: true,
			},
		],
	},
}
export const dictcodes = [
	'ORG_MATERIAL_TYPE',
	'BLOCK_CHAIN_STATUS',
	'ENERGY',
	'DEPUTY_TYPE',
	'EDUCATION',
	'FACILITY_LOCATION_TYPE',
	'COMMON_FLAG',
	'ORG_TYPE',
	'ORG_LEVEL',
	'ORG_OPERATE_STATUS',
	'ID_CARD_TYPE',
	'LEGAL_PROPERTY',
	'MEDICAL_MODE',
	'MEDICAL_INSTITUTE',
	'MEDICAL_COOPERATE_TYPE',
	'MEDICAL_INSURE_NETWORK_MODE',
	'MEDICAL_INSURE_LEVEL',
	'SERVICE_ITEM_TYPE',
	'NURSE_LEVEL',
	'OLDMAN_TYPE',
	'LAND_PROPERTY',
	'HOUSE_PROPERTY',
	'HOUSE_PROVE_STATUS',
	'OLDMAN_PRODUCT_TYPE',
	'DEVICE_TYPE',
	'FIRE_APPROVAL_STATUS',
	'PREVENT_DEPOSIT',
	'SUBSIDY_TYPE',
	'DOORSTEP_SERVICE_ITEMS',
	'COMMUNITY_SERVIC',
	'BUILDING_STRUCTURE',
	'FIRE_RESISTANCE_LEVEL',
	'FIRE_HAZARD_LEVEL',
	'FIRE_FACILITIES',
	'CONSTRUCTION_STATUS',
	'INSTITUTIONAL_NATURE'
]
export const baseConfig = {
	pageName: '养老服务组织管理',
	dictcodes,
	rowKey: 'id',
	addLabel: '采集数据',
	tipLabel: 'organizationName',
	needPigeonhole: true, // 是否显示顶部关于归档的部分
	exportMqTopic: [
		{
			topic: '/ning/export/dpServiceOrgBasePO/',
			label: '基础数据',
			code: 3013,
			po: 'dpServiceOrgBasePO',
		},
		{
			topic: '/ning/export/dpServiceOrgDevicePO/',
			label: '设施设备',
			code: 3014,
			po: 'dpServiceOrgDevicePO',
		},
		{
			topic: '/ning/export/dpServiceOrgExtendPO/',
			label: '扩展信息',
			code: 3015,
			po: 'dpServiceOrgExtendPO',
		},
		{
			topic: '/ning/export/dpServiceOrgItemsPO/',
			label: '服务项目',
			code: 3016,
			po: 'dpServiceOrgItemsPO',
		},
		{
			topic: '/ning/export/dpServiceOrgOtherPO/',
			label: '其他信息',
			code: 3017,
			po: 'dpServiceOrgOtherPO',
		},
		{
			topic: '/ning/export/dpServiceOrgProductPO/',
			label: '老年用品',
			code: 3018,
			po: 'dpServiceOrgProductPO',
		},
	],
	api: {
		moreSearch: 'view_dpServiceOrgBase_search',
		reserveSearch: 'view_dpServiceOrgBase_search',
		index: 'view_dpServiceOrgBase_page',
		add: 'view_dpServiceOrgBase_gather',
		edit: 'sysServiceOrganization_edit',
		delete: 'view_dpServiceOrgBase_del',
		export: 'view_dpServiceOrgBase_exportAll',
	},
	auth: {
		index: 'view_dpServiceOrgBase_page',
		add: 'view_dpServiceOrgBase_gather',
		edit: 'sysServiceOrganization_edit',
		delete: 'view_dpServiceOrgBase_del',
		detail: 'view_dpServiceOrgBase_view',
		mulitSet: 'mulitSet',
		import: 'view_dpServiceOrgBase_import',
		export: 'view_dpServiceOrgBase_exportAll',
	},
	menuBtn: [
		{
			icon: 'editor',
			label: '查看档案',
			type: 'primary',
			operate: 'Archives',
			auth: 'view_dpServiceOrgBase_view',
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '75%',
		// fullscreen: true
	},
	moreSearchConfig,
	reserveSearchConfig,
	detailConfig,
	searchConfig,
	beforeOnLoadFormate: async (params) => {
		if(params.organizationTypeList){
			params.organizationTypeList = params.organizationTypeList.split(',')
		}
		
		const areasObj: any = getAreaObj(params.areas, '')
		params = toSearchHandle(moreSearchConfig, reserveSearchConfig, params)
		return Promise.resolve({
			...params,
			...areasObj,
			areas: undefined,
		})
	},
	onLoadFormate: async (arr) => {
		const tableData = arr.map((item) => {
			const areasObj: any = getAreaObj(item, '', 'set')
			const nowAreaObj: any = getAreaObj(item, 'now', 'set')
			return {
				...item,
				areas_name: areasObj.names,
				nowAreasNames: nowAreaObj.names,
				tableAreaName: [item.areaName, item.streetName, item.communityName].filter(Boolean).join(''),
			}
		})
		return Promise.resolve(Object.freeze(tableData))
	},
	tableConfig,
}
